package cn.bonoon.controllers.announcement;

import java.util.List;

import cn.bonoon.entities.interacting.AnnouncementEntity;
import cn.bonoon.kernel.io.FileManager;
import cn.bonoon.kernel.util.StringHelper;

public class AnnouncementUtils {

	public static StringBuilder parseAnnouncement(List<AnnouncementEntity> announcement, FileManager fileManager) throws Exception {
		StringBuilder sb = new StringBuilder();
		for (AnnouncementEntity entity : announcement) {
			sb.append("<tr><td style='padding-top:10px;'>");
			if(entity.isTopest()){
				sb.append("<font color='red'>[置顶]</font>");
			}
			sb.append("<font style='line-height:150%;'>");
			sb.append(entity.getContent());
			sb.append("</font></td></tr>");
			
			if(entity.hasFile()){//是否上传了文件的标准判断方法是判断文件的大小是否等于0
				sb.append("<tr><td style='padding-top:10px;'><a href='");
				sb.append(fileManager.loadPath(entity));
				sb.append("' target='_blank'>下载：");
				sb.append(entity.getFilename());
				sb.append("</a></td></tr>");
			}
			
			sb.append("<tr><td style='padding-bottom:10px;border:solid #e6e6e6;border-width:0px 0px 1px 0px;'>");
			sb.append("<font style='line-height:150%;'>");
			sb.append(StringHelper.datetime2String(entity.getCreateAt())).append("</font></td></tr>");
		}
		return sb;
	}
}
